home *** CD-ROM | disk | FTP | other *** search
/ Champak 54 / Vol 54.iso / games / turttleo.swf / scripts / __Packages / Hint.as < prev    next >
Encoding:
Text File  |  2007-10-01  |  5.9 KB  |  220 lines

  1. class Hint
  2. {
  3.    var _visible;
  4.    static var hints;
  5.    static var mc;
  6.    static var active = true;
  7.    function Hint(fa, fc, lc, fmt)
  8.    {
  9.       if(Hint.hints)
  10.       {
  11.          delete this;
  12.          return undefined;
  13.       }
  14.       Hint.hints = [];
  15.       Hint.mc = _root.createEmptyMovieClip("hints_mc",16383);
  16.       Hint.mc.createTextField("tf",0,0,0,0,0);
  17.       Hint.mc.tf.autoSize = true;
  18.       Hint.mc.tf.selectable = false;
  19.       Hint.mc.lc = lc != undefined ? lc : 3355443;
  20.       Hint.mc.fc = fc != undefined ? fc : 16777164;
  21.       Hint.mc.fa = fa != undefined ? fa : 100;
  22.       Hint.mc.fmt = new TextFormat("_sans",10,3355443);
  23.       for(var i in fmt)
  24.       {
  25.          Hint.mc.fmt[i] = fmt[i];
  26.       }
  27.       TextField.prototype.addHint = Button.prototype.addHint = MovieClip.prototype.addHint = function(t)
  28.       {
  29.          var _loc2_ = Hint.hints.length;
  30.          do
  31.          {
  32.             _loc2_;
  33.             if(!_loc2_--)
  34.             {
  35.                break;
  36.             }
  37.          }
  38.          while(Hint.hints[_loc2_].o != this);
  39.          
  40.          if(t != undefined)
  41.          {
  42.             var _loc3_ = Hint.hints[_loc2_];
  43.             if(!_loc3_)
  44.             {
  45.                var _loc0_ = null;
  46.                _loc3_ = Hint.hints[Hint.hints.length] = {o:this,txt:t};
  47.             }
  48.          }
  49.          else if(Hint.hints[_loc2_])
  50.          {
  51.             Hint.hints.splice(_loc2_,1);
  52.          }
  53.          Hint.mc.onMouseMove();
  54.       };
  55.       var isParent = function(a, b)
  56.       {
  57.          while((a = a._parent) != _root)
  58.          {
  59.             if(a == b)
  60.             {
  61.                return true;
  62.             }
  63.          }
  64.          return false;
  65.       };
  66.       var getParentDepth = function(a, p)
  67.       {
  68.          while(a._parent != p)
  69.          {
  70.             a = a._parent;
  71.          }
  72.          return a.getDepth();
  73.       };
  74.       var getGeneric = function(a, b)
  75.       {
  76.          while(!isParent(a,b) && b != _root)
  77.          {
  78.             b = b._parent;
  79.          }
  80.          return b;
  81.       };
  82.       var order = function(a, b)
  83.       {
  84.          if(isParent(a.o,b.o))
  85.          {
  86.             return -1;
  87.          }
  88.          if(isParent(b.o,a.o))
  89.          {
  90.             return 1;
  91.          }
  92.          var _loc3_ = getGeneric(a.o,b.o);
  93.          return getParentDepth(a.o,_loc3_) < getParentDepth(b.o,_loc3_);
  94.       };
  95.       Hint.mc.onMouseMove = function()
  96.       {
  97.          this._visible = false;
  98.          if(!Hint.active)
  99.          {
  100.             return undefined;
  101.          }
  102.          if(!_root.hitTest(_xmouse,_ymouse,true))
  103.          {
  104.             return undefined;
  105.          }
  106.          var dbl = [];
  107.          for(var i in Hint.hints)
  108.          {
  109.             var o = Hint.hints[i].o;
  110.             if(o._x == undefined)
  111.             {
  112.                Hint.hints.splice(Number(i),1);
  113.             }
  114.             else if(o._visible && _root.hitTest.call(o,_xmouse,_ymouse,true))
  115.             {
  116.                dbl.push(Hint.hints[i]);
  117.             }
  118.          }
  119.          switch(dbl.length)
  120.          {
  121.             case 0:
  122.                return undefined;
  123.             case 1:
  124.                var up = dbl[0];
  125.                break;
  126.             default:
  127.                var up = dbl.sort(order)[0];
  128.          }
  129.          with(this)
  130.          {
  131.             if(hint != up)
  132.             {
  133.                by = _loc0_ = null;
  134.                bx = _loc0_;
  135.             }
  136.             hint = up;
  137.             _visible = _loc0_ = true;
  138.             _loc0_;
  139.             _x = _loc0_ = _root._xmouse;
  140.             _loc0_;
  141.             _y = _loc0_ = _root._ymouse;
  142.             _loc0_;
  143.             var x = _x + _width < Stage.width;
  144.             var y = _y - _height < 0;
  145.             if(bx != x)
  146.             {
  147.                bx = x;
  148.                if(by == y)
  149.                {
  150.                   drawHint();
  151.                }
  152.             }
  153.             if(by != y)
  154.             {
  155.                by = _loc0_ = y;
  156.                _loc0_;
  157.                drawHint();
  158.             }
  159.          }
  160.          updateAfterEvent();
  161.       };
  162.       Hint.mc.drawHint = function()
  163.       {
  164.          var dr = 8;
  165.          with(this)
  166.          {
  167.             tf.text = hint.txt;
  168.             tf.setTextFormat(fmt);
  169.             var w = tf._width;
  170.             var h = tf._height;
  171.             var sx = tf._x = !bx ? - w - dr : dr;
  172.             var sy = tf._y = !by ? - h - dr : dr;
  173.             clear();
  174.             var i = 5;
  175.             var n = 8;
  176.             while(i--)
  177.             {
  178.                beginFill(0,3);
  179.                var ux = sx + n - i;
  180.                var lx = sx + w + i;
  181.                var uy = sy + n - i;
  182.                var ly = sy + h + i;
  183.                var r = n - i;
  184.                var f = 0.707106781186548 * r;
  185.                var a = 0.588186525863094 * r;
  186.                var b = 0.00579432557070009 * r;
  187.                var cx = lx - r;
  188.                var cy = uy + r;
  189.                moveTo(ux + r,uy);
  190.                lineTo(cx,uy);
  191.                curveTo(lx - a,uy + b,cx + f,cy - f);
  192.                curveTo(lx - b,uy + a,lx,uy + r);
  193.                cy = ly - r;
  194.                lineTo(lx,cy);
  195.                curveTo(lx - b,ly - a,cx + f,cy + f);
  196.                curveTo(lx - a,ly - b,lx - r,ly);
  197.                cx = ux + r;
  198.                lineTo(cx,ly);
  199.                curveTo(ux + a,ly - b,cx - f,cy + f);
  200.                curveTo(ux - b,ly - a,ux,ly - r);
  201.                cy = uy + r;
  202.                lineTo(ux,cy);
  203.                curveTo(ux + b,uy + a,cx - f,cy - f);
  204.                curveTo(ux + a,uy + b,ux + r,uy);
  205.                endFill();
  206.             }
  207.             lineStyle(0,lc,50);
  208.             beginFill(fc,fa);
  209.             moveTo(sx,sy);
  210.             lineTo(sx + w,sy);
  211.             lineTo(sx + w,sy + h);
  212.             lineTo(sx,sy + h);
  213.             lineTo(sx,sy);
  214.             endFill();
  215.          }
  216.          updateAfterEvent();
  217.       };
  218.    }
  219. }
  220.